package com.fs.user.web;

import com.fs.entity.User;
import com.fs.service.UserService;
import com.fs.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/UpdateUserSubmitServlet")
public class UpdateUserSubmitServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /**
         * 1.编码
         * 2.获取请求参数
         * 3.调用业务层的方法
         * 4.响应结果
         */

        int id =Integer.parseInt(request.getParameter("id"));
        String name = request.getParameter("name");
        String sex = request.getParameter("sex");
        int age = Integer.parseInt(request.getParameter("age"));
        String address = request.getParameter("address");
        String qq = request.getParameter("qq");
        String email = request.getParameter("email");


       //封装成一个User对象
        User user = new  User(name,sex,age,address,email,qq);
        user.setId(id);

        UserService userService = new UserServiceImpl();
        userService.updateUser(user);
        //跳转到 ListServlet  重定向
       response.sendRedirect("/ListServlet");

    }


}
